﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Contexts;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace AppDomainTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("CurrentAppDomain start!");
            Console.WriteLine("CurrentDomain.FriendlyName:" + AppDomain.CurrentDomain.FriendlyName);
            AppDomain newAppDomain = AppDomain.CreateDomain("newAppDomian");
            CrossAppDomainDelegate crossAppDomainDelegate = new CrossAppDomainDelegate(MyCallBack);
            newAppDomain.DomainUnload += (obj, e) =>
            {
                Console.WriteLine("NewAppDomain unload!");
            };
            newAppDomain.DoCallBack(crossAppDomainDelegate);
            AppDomain.Unload(newAppDomain);
            Console.ReadKey();
        }

        static public void MyCallBack()
        {
            string name = AppDomain.CurrentDomain.FriendlyName;
            for (int n = 0; n < 4; n++)
                Console.WriteLine(string.Format(" Do work in {0}......", name));
        }
    }
}
